/*
 * Created on 28/02/2004
 *
 * To change the template for this generated file go to
 * Window - Preferences - Java - Code Generation - Code and Comments
 */
package org.potiorb.orb.poa;

import java.util.HashMap;

import org.potiorb.orb.portable.ObjectId;
import org.potiorb.orb.portable.ObjectRef;


public class POAManager
{
	private State state = State.HOLDING;
	private HashMap Servants;
	private int poakey;
    private Servant m_serv;

	public POAManager()
        {
          Servants = new HashMap();
          poakey = 0;
        }
        public Servant LocateServant(ObjectRef pObjectRef){
          String _key = new String();
          _key = pObjectRef.getKeyobject();
          System.out.println("Tamanho:"+Servants.size());
          Servant ser = (Servant)Servants.get(_key);
          return m_serv;
	}
	public ObjectId addServant(Servant pServant){
		ObjectRef _ref = new ObjectRef();
		_ref.setHost("127.0.0.1");
		_ref.setPort("11000");
		_ref.setKeyobject(""+poakey);

		pServant._set_delegate(_ref);

                String _key = new String();
                _key = ""+poakey;
                m_serv = pServant;
		Servants.put(_key, pServant);

		ObjectId _id = new ObjectId();
		_id._set_delegate(_ref);
		return _id;
	}

	public void activate() {
		state = State.ACTIVE;
	}
	public void deactivate(boolean etherealize_objects, boolean wait_for_completion){
		state = State.INACTIVE;
	}
	public void discard_requests(boolean wait_for_completion){
		state = State.DISCARDING;
	}
	public State get_state() {
		return state;
	}
	synchronized protected POA getRegisteredPOA(String name) {
		return null;
	}
	public void hold_requests(boolean wait_for_completion){
		state = State.HOLDING;
	}
	private boolean isInInvocationContext() {
		return false;
	}
	synchronized protected void registerPOA(POA poa) {
	}
	synchronized protected void unregisterPOA(POA poa) {
	}
}
